<template>
	<cl-page>
		<view class="page">
			<view class="form">
				<cl-form label-position="top">
					<cl-form-item label="备注">
						<cl-input v-model="form.name" type="name" :border="false" :height="80" :border-radius="12"
							:placeholder="elephantNumber" />
					</cl-form-item>
				</cl-form>
			</view>

			<cl-footer>
				<cl-button size="default" fill round type="primary" :loading="loading" @tap="save">
					保存
				</cl-button>
			</cl-footer>
		</view>
	</cl-page>
</template>

<script lang="ts" setup>
	import { reactive, ref } from "vue";
	import { useCool } from "/@/cool";
	import { useUi } from "/$/cool-ui";
	import { onLoad } from "@dcloudio/uni-app";
	const { router, service } = useCool();
	const ui = useUi();

	const loading = ref(false);
	const elephantNumber = ref("")
	const form = reactive({
		name: "",
		id: 0
	});

	async function save() {
		if (!form.id) {
			ui.showToast("id不存在")
			setTimeout(() => {
				router.home()
			}, 1000)
			return
		}
		loading.value = true;
		console.log(form)
		await service.broadcast.record.update(form).catch((err) => {
			ui.showToast(err.message);
		});
		loading.value = false;
		ui.showToast("备注成功")
		setTimeout(() => {
			router.back()
		}, 1000)
	}
	onLoad((options) => {
		form.id = Number(options?.id)
		elephantNumber.value = options?.elephantNumber
	})
</script>

<style lang="scss" scoped>
	.page {
		.form {
			padding: 20rpx 24rpx;
		}
	}
</style>